package com.qef.com.mmovie.entity;

import android.app.Activity;

import com.avos.avoscloud.AVUser;
import com.qef.com.mmovie.App;
import com.qef.com.mmovie.utils.ToastUtil;
import com.qef.com.mmovie.utils.UIHelper;

/**
 * Created by guangjiego on 2017/5/16.
 */

public class User {
    public static AVUser getCurrenUser() {
        return AVUser.getCurrentUser();
    }

    public static void saveUserInfo() {
        AVUser.getCurrentUser().saveInBackground();
    }

    public static Object getHead() {
        return getCurrenUser().get("head");
    }

    public static Object getAlias() {
        return getCurrenUser().get("alias");
    }

    public static void setAlias(String name) {
        AVUser.getCurrentUser().put("alias", name);
        AVUser.getCurrentUser().saveInBackground();
    }

    public static boolean isLogin() {
        AVUser currentUser = AVUser.getCurrentUser();
        return currentUser != null;
    }

    public static boolean isLoginToLogin(Activity activity) {
        AVUser currentUser = AVUser.getCurrentUser();
        if(currentUser == null){
            ToastUtil.showToast(App.getInstance(), "您还没登陆呢！赶紧登陆吧！");
            UIHelper.goLoginActivity(activity);
        }
        return currentUser != null;
    }

    public static void exit() {
        AVUser.logOut();
    }

    public static void resetPwd(String newPwd) {
        AVUser.getCurrentUser().setPassword(newPwd);
        AVUser.getCurrentUser().saveInBackground();
    }
}
